package tcpGroupChat;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Server {
    //创建在线socket集合
    public static List<Socket> onLineList = new ArrayList<>();
    public static void main(String[] args) throws Exception {
        //创建ServerSocket对象，同时为服务端注册端口
        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("------服务端启动------");
        Socket socket = null;
        try {
            while (true) {
                //使用ServerSocket对象，调用accept方法，等到客户端链接
                socket = serverSocket.accept();
                //每接受一个socket就将其存在集合内部
                onLineList.add(socket);
                System.out.println("ip地址为" + socket.getRemoteSocketAddress() + "上线了！！！");
                //线程启动
                new ServerReadThread(socket).start();
            }
        } catch (Exception ignored) {

        }
    }
}
